﻿using System;
using PowerToolsWeb.DataAccess;
using PowerToolsWeb.Entities;
using PowerToolsWeb.Facade;

namespace PowerToolsWeb
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
#if(DEBUG)
            AutoLogin();
#endif
        }
        void AutoLogin()
        {
            SystemUser sysUser = new SystemUser();
            sysUser.UserName = "admin";
            Session["SystemUser"] = sysUser;
            if (Request.QueryString["url"] != null)
                Response.Redirect(Request.QueryString["url"].ToString());
            else
                Response.Redirect("Admin/Default.aspx");
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txbUserName.Text == "" || txbPwd.Text == "")
            {
                AdminPageBase.Alert(Page, "请完整输入用户名和密码");
                return;
            }
            Tpt_Admin user = new Tpt_Admin();
            if (!user.GetPwdByUserName(txbUserName.Text.Trim()))
            {
                AdminPageBase.Alert(Page, "用户名有误");
                return;
            }
            if (user.PWD != txbPwd.Text.Trim())
            {
                AdminPageBase.Alert(Page, "密码有误");
                return;
            }
            SystemUser sysUser = new SystemUser();
            sysUser.UserName = user.LOGINNAME;
            Session["SystemUser"] = sysUser;
            if (Request.QueryString["url"] != null)
                Response.Redirect(Request.QueryString["url"].ToString());
            else
                Response.Redirect("Admin/Default.aspx");
        }
    }
}
